# -*- coding: utf-8 -*-
"""
@Time ： 2024/3/12 15:42
@Auth ： gc
"""

# 计算购入成本
import math


def computer_buy_cost(stock_number, buy_stock_price, commission_rate = 3/10000, transfer_fee_rate = 2/100000):
    """
    :param stock_number:
    :param buy_stock_price:
    :param commission_rate: 佣金，买入卖出都收取
    :param transfer_fee_rate:过户费，买入卖出都收取
    :return:
    """
    stock_money = stock_number*buy_stock_price
    commission = stock_money*commission_rate
    if commission<=5:
        commission = 5
    transfer_fee = stock_money*transfer_fee_rate
    return stock_money + commission + transfer_fee


# 计算卖出收入
def computer_sell_cost(stock_number, sell_stock_price, commission_rate = 3/10000,   stamp_duty_rate = 5/10000, transfer_fee_rate = 2/100000):
    """
    :param stock_number:
    :param sell_stock_price:
    :param commission_rate: 佣金，买入卖出都收取
    :param stamp_duty_rat:印花税 卖出收取
    :param transfer_fee_rate:过户费，买入卖出都收取
    """
    stock_money = stock_number*sell_stock_price
    commission = stock_money*commission_rate
    if commission<=5:
        commission = 5
    transfer_fee = stock_money*transfer_fee_rate
    stamp_duty = stock_money*stamp_duty_rate
    return stock_money - commission - transfer_fee - stamp_duty


# 计算收益
def computer_income(stock_number, buy_stock_price, sell_stock_price, commission_rate = 3/10000,   stamp_duty_rate = 5/10000, transfer_fee_rate = 2/100000):
    return computer_sell_cost(stock_number, sell_stock_price, commission_rate, stamp_duty_rate, transfer_fee_rate) - computer_buy_cost(stock_number, buy_stock_price, commission_rate, transfer_fee_rate)

# 计算最低卖出价格
def computer_min_sell_price(stock_number, buy_stock_price, commission_rate = 3/10000,   stamp_duty_rate = 5/10000, transfer_fee_rate = 2/100000):
    min_sell_price = buy_stock_price + 0.01
    while True:
        income = computer_income(stock_number, buy_stock_price, min_sell_price, commission_rate, stamp_duty_rate, transfer_fee_rate)
        if income>0:
            return round(min_sell_price, 2)
        else:
            min_sell_price += 0.01


if __name__ == '__main__':
    # print(computer_income(100, 1745, 1746))
    # print(computer_min_sell_price(100, 1745))
    # print(computer_income(2000, 10, computer_min_sell_price(2000, 10)))
    number_stock = 200
    price_stock = 72.80
    print(f"买入股票数量：{number_stock}, 买入价：{price_stock}，最小卖出价：{computer_min_sell_price(number_stock, price_stock)}，收益：{computer_income(number_stock, price_stock, computer_min_sell_price(number_stock, price_stock))}")
    print(computer_income(200, 72.9, 73.2))

